package learn_250211;

import java.lang.Math;

public class leetcode {
    public static void main(String[] args) {
        System.out.print(lengthOfLongestSubstring("dvdf"));
    }
    public static int lengthOfLongestSubstring(String s) {
        if (s==null){
            return 0;
        }
        if(s.length() == 1){
            return 1;
        }
        int left = 0;
        int right = 0;
        int maxlen = 0;
        while(right<s.length()-1){
            right++;
            char in = s.charAt(right);
            String sub = s.substring(left,right);
            while((check_inSub(sub,in))&&left!=right){
                left++;
                sub = s.substring(left,right);
            }
            maxlen = Math.max(maxlen,right-left+1);

        }
        return maxlen;

    }

    public static boolean check_inSub(String str,char a){
        if(str.indexOf(a) >= 0){
            return true;
        }
        return false;
    }
}
